#pragma GCC optimize(2, "Ofast", "inline")
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <algorithm>
#define endl '\n'
#define int long long
#define pii pair<int, int>
using namespace std;
const int MOD = 998244353;
const int MXN = 2e5 + 5;

int n, m;
string s[11];
string ans[1111][11];
string tmp[11];// 当前的矩阵
int cnt = 0;

void check(string tmp[])
{
    int flag = 1;
    for (int i = 0;i < cnt;++i)
    {
        flag = 1;
        for (int j = 0;j < m;++j)
        {
            if (tmp[j] != ans[i][j])
            {
                flag = 0;
                break;
            }
        }
        if (flag == 1) return;
    }
    for (int i = 0;i < m;++i)
    {
        ans[cnt][i] = tmp[i];
    }
    cnt++;
}
signed main()
{
    // 输入输出优化
    cin.tie(0)->sync_with_stdio(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 0;i < n;++i)
    {
        cin >> s[i];
    }
    for (int i = 0;i <= n - m;++i)
    {
        for (int j = 0;j <= n - m;++j)
        {
            for (int k = 0;k < m;++k)
            {
                tmp[k] = s[i + k].substr(j, m);// 第i+j行提取m列
            }
            check(tmp);
        }
    }
    cout << cnt << endl;
    return 0;
}